package www.openteam.com.model.realtime;

import android.support.annotation.NonNull;

import java.util.List;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.ProStock;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2017/1/5.
 */

public class StockModel extends BaseModel {

            private boolean isQuery =false;

    public  boolean queryStock(@NonNull String rdsno,
                               @NonNull String stype,
                               @NonNull int PageSize,@NonNull final
                               StockOnListener stockOnListener
                               ){
            httpApiService.queryStock(rdsno, stype,PageSize)
                    .compose(new CommonTransformer<ProStock>())
                    .subscribe(new CommonSubscriber<ProStock>(OTApplication.getmContext()) {
                        @Override
                        public void onNext(ProStock proStock) {
                            isQuery=true;
                            stockOnListener.querySSuccess(proStock.getData());
                        }

                        @Override
                        protected void onError(ApiException e) {
                            super.onError(e);
                            isQuery=false;
                            stockOnListener.querySFail(e.message);
                        }
                    });
            return  isQuery;
    }



    public interface StockOnListener {

        void querySSuccess(List<ProStock.DataEntity> produce);

        void querySFail(String failMsg);
    }

}
